package com.jlkf.service.impl;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jlkf.dao.SystemMapper;
import com.jlkf.dao.TblCourseMapper;
import com.jlkf.dao.TblOrderMapper;
import com.jlkf.dao.TblOtherCourseMapper;
import com.jlkf.dao.TblProblemMapper;
import com.jlkf.dao.TblSortMapper;
import com.jlkf.dao.TblUserPurseInfoMapper;
import com.jlkf.dao.TblVipInfoMapper;
import com.jlkf.pojo.TblCourse;
import com.jlkf.pojo.TblOrder;
import com.jlkf.pojo.TblOtherCourse;
import com.jlkf.pojo.TblSort;
import com.jlkf.pojo.TblUserPurseInfo;
import com.jlkf.pojo.TblVipInfo;
import com.jlkf.service.CourseInfoService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.CfbpayDemoUtils;
import com.platform.server.util.MD5Util;
import com.platform.server.util.PlatUtils;
import com.platform.server.util.RSA;
import com.platform.server.util.RSAUtil;
import com.platform.server.util.RegexUtil;
import com.platform.server.util.StringTools;
import com.platform.server.util.UUIDUtil;
import com.platform.server.util.WxpayDemoUtils;

@Service
public class CourseInfoServiceImpl implements CourseInfoService {

	private static final String Long = null;

	private static final String Date = null;

	@Autowired
	private TblSortMapper tblSortMapper;
	
	@Autowired
	private TblCourseMapper tblCourseMapper;
	
	@Autowired
	private TblOrderMapper tblOrderMapper;

	@Autowired
	private TblUserPurseInfoMapper tblUserPurseInfoMapper;
	
	@Autowired
	private TblVipInfoMapper tblVipInfoMapper;
	
	@Autowired
	private TblOtherCourseMapper tblOtherCourseMapper;
	
	@Autowired
	private TblProblemMapper tblProblemMapper;
	
	@Autowired
	private SystemMapper systemMapper;
	
	/**
	 * 查看课程一级分类
	 */
	@Override
	public ReturnData selectCourseOneStair() {
		List<Map<String,Object>> lists = tblSortMapper.selectCourseOneStair(0);
		return new ReturnData(lists,200,"成功");
	}
	
	/**
	 * 查看课程二级跟三级分类
	 */
	@Override
	public ReturnData selectCourseTwoStair(Integer id) {
		if(id == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = tblSortMapper.selectCourseOneStair(id);
		for(int i = 0;i < lists.size();i++){
			Long gid = (Long) lists.get(i).get("G_ID");
			List<Map<String, Object>> arrayList = tblSortMapper.selectCourseOneStair(gid.intValue());
			Map<String, Object> map = lists.get(i);
			map.put("threeLevel", arrayList);
		}
		return new ReturnData(lists,200,"成功");
	}
	
	/**
	 * 查看课程三级分类
	 */
	@Override
	public ReturnData selectCourseThreeStair(Integer id) {
		if(id == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> arrayList = tblSortMapper.selectCourseOneStair(id);
		return new ReturnData(arrayList,200,"成功");
	}
	
	/**
	 * 查看特色课程一级分类
	 */
	@Override
	public ReturnData selectFeatureCourseOneStair() {
		List<Map<String,Object>> lists = tblSortMapper.selectFeatureCourseOneStair(0);
		return new ReturnData(lists,200,"成功");
	}
	
	/**
	 * 查看特色课程二级跟三级分类
	 */
	@Override
	public ReturnData selectFeatureCourseTwoStair(Integer id) {
		if(id == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = tblSortMapper.selectFeatureCourseOneStair(id);
		for(int i = 0;i < lists.size();i++){
			Long gid = (Long) lists.get(i).get("G_ID");
			List<Map<String, Object>> arrayList = tblSortMapper.selectFeatureCourseOneStair(gid.intValue());
			Map<String, Object> map = lists.get(i);
			map.put("threeLevel", arrayList);
		}
		return new ReturnData(lists,200,"成功");
	}
	
	/**
	 * 查看特色课程三级分类
	 */
	@Override
	public ReturnData selectFeatureCourseThreeStair(Integer id) {
		if(id == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> arrayList = tblSortMapper.selectFeatureCourseOneStair(id);
		return new ReturnData(arrayList,200,"成功");
	}

	/**
	 * pc端热搜列表
	 */
	@Override
	public ReturnData selectTopSearch() {
		String[] autoTopSearch = tblCourseMapper.selectAutoTopSearch();
		String[] topSearch = tblCourseMapper.selectTopSearch();
		List<String> list = new ArrayList(Arrays.asList(autoTopSearch));
		list.addAll(Arrays.asList(topSearch));
		String[] str = new String[list.size()];
		list.toArray(str);
		String[] top = new String[3];
		if(str.length > 2){
			for(int i = 0;i < 3;i++){
				top[i] = str[i];
			}
		}
		return new ReturnData(top,200,"成功");
	}

	 /**
     * 查看课程分类视频列表
     */
	@Override
	public ReturnData selectCourseSortList(Integer one_stair_id,Integer two_stair_id,Integer three_stair_id,Integer difficulty,String type,String param,Integer pageSize, Integer pageNo) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("one_stair_id", one_stair_id);
		map.put("two_stair_id", two_stair_id);
		map.put("three_stair_id", three_stair_id);
		map.put("difficulty", difficulty);
		map.put("type", type);
		map.put("param", param);
		PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		List<TblCourse> lists = tblCourseMapper.selectCourseSortList(map);
		String lessonid = "";
		for(int i = 0;i < lists.size();i++){
			if(lists.get(i).getgCourseScore() == null || lists.get(i).getgCourseScore() == 0){
				lists.get(i).setgCourseScore(5D);
			};
			lessonid += lists.get(i).getgRelatedCourse() + ",";
			String[] split = lists.get(i).getgRelatedCourse().split(",");
			List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(split[0]);
			lists.get(i).setTeacherName(lessonList.get(0).get("teacher_name").toString());
		}
		if("2".equals(param)){
			Collections.sort(lists, new Comparator<TblCourse>() {
				public int compare(TblCourse o1, TblCourse o2) {
					return (o2.getgLeamNum()).compareTo((Integer) o1.getgLeamNum());
				}
			});
		}
		PageInfo<TblCourse> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists, pageInfo.getPages(),(int)pageInfo.getTotal(),200, "成功");
	}

	/**
     * pc端搜索课程或老师列表
     */
	@Override
	public ReturnData searchCourseandTeacher(String content,Integer difficulty,String type,Integer teacherid,String param,Integer pageSize, Integer pageNo) {
		//搜索课程列表
		Map<String,Object> hashMap = new HashMap<String,Object>();
		hashMap.put("content", content);
		hashMap.put("difficulty", difficulty);
		hashMap.put("type", type);
		hashMap.put("teacherid", teacherid);
		hashMap.put("param", param);
		PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		List<Map<String, Object>> lists = tblCourseMapper.searchCourse(hashMap);
		for(int i = 0;i < lists.size();i++){
			if(lists.get(i).get("gCourseScore") == null || (Double)lists.get(i).get("gCourseScore") == 0){
				lists.get(i).put("gCourseScore", 5);
			}
		}
		//搜索老师列表
		/*List<Map<String, Object>> teacherList = new ArrayList<>();;
		if(!StringTools.isEmpty(content)){
			teacherList = tblCourseMapper.searchTeacher(content);
		}
		Map<String,Object> map = new HashMap<>();
		map.put("courseList", courseList);
		map.put("teacherList", teacherList);*/
		if("2".equals(param)){
			Collections.sort(lists, new Comparator<Map<String, Object>>() {
				public int compare(Map<String, Object> o1, Map<String, Object> o2) {
					return (((Integer) o1.get("gLeamNum")).compareTo((Integer)o2.get("gLeamNum")));
				}
			});
		}
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists, pageInfo.getPages(),(int)pageInfo.getTotal(),200, "成功");
	}

	 /**
     * 课程目录列表
     */
	@Override
	public ReturnData selectCourseCatalogList(Integer courseid,Integer userid) {
		if(courseid == null){
			return new ReturnData(12,"参数有误");
		}
		//查看课程下面的课时
		Map<String, Object> map = tblCourseMapper.selectCourseInfo(courseid, null);
		//查看用户购买过的课时
		//String[] lessons = tblCourseMapper.selectUserPayLesson(courseid, userid);
		String[] lessons = tblCourseMapper.byselectUserPayLesson(userid);
		List<String> arrayList = new ArrayList<>();
		List<Map<String, Object>> lists = new LinkedList<>();
		for(int i = 0;i < lessons.length;i++){
			String[] less = lessons[i].split(",");
			for(int j = 0;j < less.length;j++){
				arrayList.add(less[j]);
			}
		}
		String[] split = map.get("G_RELATED_COURSE").toString().split(",");
		for(int i = 0;i < split.length;i++){
			Map<String,Object> hashMap = new HashMap<>();
			hashMap.put("lessonid", Integer.parseInt(split[i]));
			hashMap.put("userid", userid);
			hashMap.put("courseid", courseid);
			List<Map<String, Object>> lis = tblCourseMapper.selectCourseCatalogList(hashMap);
			lists.add(lis.get(0));
		}
		if(lists.size() == 0){
			return new ReturnData(100,"暂无数据");
		}
		for(int i = 0;i < lists.size();i++){
			for(int j = 0;j < arrayList.size();j++){
				if(arrayList.get(j).equals(lists.get(i).get("G_ID").toString())){
					lists.get(i).put("is_buy", "已购买");
				}
			}
		}
		for(int i = 0;i < lists.size();i++){
			lists.get(i).put("G_LESSON_CATALOG", "课时" + (i + 1));
			if(lists.get(i).get("is_buy") == null){
				lists.get(i).put("is_buy", "未购买");
			}
		}
		Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
		Integer isvip = 0;
		if(userInfo != null && userInfo.get("isvip") != null && (Long)userInfo.get("isvip") > 0){
			isvip = 1;
		}	
		for(int i = 0;i < lists.size();i++){
			lists.get(i).put("isvip", isvip);
		}
		return new ReturnData(lists,200,"成功");
	}

	 /**
     * pc端推荐课程列表
     */
	@Override
	public ReturnData selectRecommendCourseList(Integer userid) {
		if(userid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = tblCourseMapper.selectRecommendCourseList(userid);
		if(lists.size() == 0){
			return new ReturnData(100,"暂无数据");  
		}
		List<Map<String,Object>> arrayList = new LinkedList<>();
		if(lists.size() > 3){
			for(int i = 0;i < 4;i++){
				arrayList.add(lists.get(i));
			}
			return new ReturnData(arrayList,200,"成功");
		}
		return new ReturnData(lists,200,"成功");
	}

	 /**
     * pc端课程详情
     */
	@Override
	public ReturnData selectCourseInfo(Integer courseid, Integer userid) {
		if(courseid == null){
			return new ReturnData(12,"参数有误");
		}
		Map<String, Object> courseInfo = tblCourseMapper.selectCourseInfo(courseid,userid);
		if(courseInfo == null){
			return new ReturnData(100,"未找到相关信息");
		}
		Double G_COURSE_SCORE = (Double)courseInfo.get("G_COURSE_SCORE");
		if(G_COURSE_SCORE == null || G_COURSE_SCORE == 0){
			courseInfo.put("G_COURSE_SCORE", 5);
		}
		//查看该用户有没有评价过
		int flag = tblCourseMapper.selectUserCommentNum(userid,courseid);
		if(flag > 0){
			courseInfo.put("isComment", 1);
		}else{
			courseInfo.put("isComment", 0);
		}
		//折扣价
		 Integer G_DISCOUNT = (Integer)courseInfo.get("G_DISCOUNT");
		if(G_DISCOUNT != null && G_DISCOUNT > 0){
			Double G_COURSE_VIP_DISCOUNT = (Double)courseInfo.get("G_COURSE_MONEY") * (G_DISCOUNT.doubleValue() / 100);
			courseInfo.put("G_COURSE_VIP_DISCOUNT", G_COURSE_VIP_DISCOUNT);
		}
		 //查看用户是否有收藏该课程
		int isCollect = tblCourseMapper.selectIsCollect(courseid, userid);
		if(isCollect > 0){
			isCollect = 1;
		}
		int isStudy = 1,isPayLesson = 0;
		//查看用户是否有购买该课程
		String lesson_id = (String) courseInfo.get("G_RELATED_COURSE");
		String[] lesson = lesson_id.split(",");
		for(int i = 0;i < lesson.length;i++){
			Map<String,Object> hashMap = new HashMap<>();
			//hashMap.put("courseid", courseid);
			hashMap.put("userid", userid);
			hashMap.put("lessonid", lesson[i]);
			int study = tblCourseMapper.selectIsStudy(hashMap);
			if(study == 0){
				isStudy = 0;
			}else{
				isPayLesson = 1;
			}
		}
		//查看用户学习了几门课时
		int studyNums = tblCourseMapper.selectStudyNums(courseid, userid);
		//查看三级分类
		Integer sortid = (Integer)courseInfo.get("G_COUSER_SORT_ID");
		TblSort tblSort = tblSortMapper.selectByPrimaryKey(sortid.longValue());
		//查看二级分类
		TblSort tblSort1 = tblSortMapper.selectByPrimaryKey(tblSort.getgSuper());
		//查看一级分类   
		TblSort tblSort2 = tblSortMapper.selectByPrimaryKey(tblSort1.getgSuper());
		courseInfo.put("threeLevel", tblSort.getgName());	//三级分类名称
		courseInfo.put("twoLevel", tblSort1.getgName());	//二级分类名称
		courseInfo.put("oneLevel", tblSort2.getgName());	//一级分类名称
		courseInfo.put("isPayLesson", isPayLesson);	
		courseInfo.put("studyNums", studyNums);	
		courseInfo.put("isCollect", isCollect);
		courseInfo.put("isStudy", isStudy);
		//查看用户信息
		Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
		if(userInfo != null){
			courseInfo.put("isvip", userInfo.get("isvip"));
		}else{
			courseInfo.put("isvip", 0);
		}
		//查看积分设置
		Integer get_integral = 0;
		Map<String,Object> hashMap = new HashMap<>();
		hashMap.put("lessonid", courseInfo.get("G_RELATED_COURSE"));
		List<Map<String, Object>> lists = tblCourseMapper.selectCourseCatalogList(hashMap);
		for(int i = 0;i < lists.size();i++){
			get_integral += Integer.parseInt(lists.get(i).get("get_integral").toString());
		}
		courseInfo.put("get_integral", get_integral);
		//查看用户最近播放的课时
		Integer recentlyPlayed = tblCourseMapper.selectRecentlyPlayed(userid,courseid);
		courseInfo.put("recentlyPlayed", recentlyPlayed);
		return new ReturnData(courseInfo,200,"成功");
	}

	/**
	 * 确认订单
	 */
	@Override
	public ReturnData sureOrder(Integer userid, Integer courseid,String lessid) {
		if(userid == null || courseid == null || lessid == null){
			return new ReturnData(12,"参数有误");
		}
		//查看课程下面的课时数
		List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(lessid);
		//查看用户已经购买的课时
		List<Map<String, Object>> courseList = tblCourseMapper.selectPurchaseLesson(userid);
		List<Map<String,Object>> lists = new ArrayList<>();
		for(int i = 0;i < courseList.size();i++){
			String lesson = (String)courseList.get(i).get("G_GOODS_ID");
			String[] lessonid = lesson.split(",");
			for(int j = 0;j < lessonList.size();j++){
				for(int k = 0;k < lessonid.length;k++){
					if(lessonList.get(j).get("G_ID").toString().equals(lessonid[k])){  
						lessonList.get(j).put("TOTAL_MONEY", courseList.get(i).get("G_ORDER_PAY_MONEY"));
						lists.add(lessonList.get(j));
					}
				}
			}
		}
		Double purchase = 0D;	//已购视频的总价格
		Integer G_LESSON_INTEGEAL = 0;	//课时积分
		for(int i = 0;i < lists.size();i++){
			purchase += (Double)lists.get(i).get("TOTAL_MONEY");
			G_LESSON_INTEGEAL += (Integer)lists.get(i).get("G_LESSON_INTEGEAL");
		}
		//查看课程信息
		Map<String, Object> courseDetails = tblCourseMapper.selectCourseDetails(courseid);
		if(courseDetails == null){
			return new ReturnData(100,"暂无数据");
		}
		//应付价格
		Double money = (Double)courseDetails.get("G_COURSE_MONEY");
		money -= purchase;
		Integer discount = (Integer)courseDetails.get("G_DISCOUNT");
		DecimalFormat df = new DecimalFormat("#.00");
		if(discount != null && discount > 0){
			money = Double.parseDouble(df.format(money * (discount.doubleValue() / 100D)));
		}
		//查看一般课程会员折扣最高的折扣比
		Integer G_COURSE_LABEL = tblVipInfoMapper.selectMaxDiscount();
		courseDetails.put("G_COURSE_LABEL", G_COURSE_LABEL);
		//查看用户信息(是否是vip)
		Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
		Map<String, Object> vipInfo = tblVipInfoMapper.selectVipInfo((Integer)userInfo.get("G_USER_IS_VIP"));
		if(vipInfo != null){
			if((Long)userInfo.get("isvip") > 0){
				G_COURSE_LABEL = (Integer) vipInfo.get("general_course_discount");   	
				if(G_COURSE_LABEL != null){
					courseDetails.put("G_COURSE_LABEL", G_COURSE_LABEL);
					money = Double.parseDouble(df.format(money * (G_COURSE_LABEL.doubleValue() / 100D)));
				}
			}
		}
		//查看平台费用折扣
		Integer platformDiscount = tblCourseMapper.selectPlatformDiscount();
		if(platformDiscount != null && platformDiscount > 0){
			money = money * (platformDiscount.doubleValue() / 100D);
		}
		courseDetails.put("money", money.intValue());
		courseDetails.put("integral", userInfo.get("G_USER_INTEGRAL"));
		courseDetails.put("vipMoney", (int)(money - money * (G_COURSE_LABEL.doubleValue() / 100D)));
		courseDetails.put("isvip", userInfo.get("isvip"));
		courseDetails.put("purchase", purchase.intValue());
		courseDetails.put("courseIntegral", (Integer)courseDetails.get("G_COURSE_INTEGEAL") - G_LESSON_INTEGEAL);
		//查看该课程可兑换多少积分
		Integer convertIntegral = 0;
		for(int i = 0;i < lessid.split(",").length;i++){
			String convert = tblCourseMapper.selectIntegral(Integer.parseInt(lessid.split(",")[i]));
			convertIntegral += Integer.parseInt(convert);
		}
		courseDetails.put("convertIntegral", convertIntegral);
		Map<String,Object> hashMap = new HashMap<>();
		hashMap.put("courseDetails", courseDetails);
		hashMap.put("lists", lists);
		return new ReturnData(hashMap,200,"成功");
	}
	
	/**
	 * 单个课时确认订单
	 */
	@Override
	public ReturnData singleSureOrder(Integer userid,Double money,Integer lessonid) {
		if(userid == null || money == null || lessonid == null){
			return new ReturnData(12,"参数有误");
		}
		Double actuallyMoney = money;
		Map<String,Object> hashMap = new HashMap<>();
		DecimalFormat df = new DecimalFormat("#.00");
		//查看单个课时会员折扣最高的折扣比
		Integer vipDiscount = tblVipInfoMapper.selectSingleMaxDiscount();
		//查看用户信息(是否是vip)
		Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
		Map<String, Object> vipInfo = tblVipInfoMapper.selectVipInfo((Integer)userInfo.get("G_USER_IS_VIP"));
		//查看vip的折扣百分比
		if(vipInfo != null){
			if((Long)userInfo.get("isvip") > 0){
				vipDiscount = (Integer) vipInfo.get("single_course_discount");   	
				if(vipDiscount != null && vipDiscount > 0){
					actuallyMoney = Double.parseDouble(df.format(money * (vipDiscount.doubleValue() / 100D)));
				}
			}
		}
		//查看平台费用折扣
		Integer platformDiscount = tblCourseMapper.selectPlatformDiscount();
		if(platformDiscount != null && platformDiscount > 0){
			actuallyMoney = actuallyMoney * (platformDiscount.doubleValue() / 100D);
		}
		//查看该课时可兑换多少积分  
		String convertIntegral = tblCourseMapper.selectIntegral(lessonid);
		hashMap.put("convertIntegral", convertIntegral);
		hashMap.put("vipMoney", (int)(money - money * (vipDiscount.doubleValue() / 100D)));
		hashMap.put("money", money.intValue());
		hashMap.put("integral", userInfo.get("G_USER_INTEGRAL"));
		hashMap.put("isvip", userInfo.get("isvip"));
		hashMap.put("actuallyMoney", actuallyMoney.intValue());
		hashMap.put("vipDiscount", vipDiscount);
		return new ReturnData(hashMap,200,"成功");
	}
	

	/**
	 * 确认支付
	 */
	@Override
	public ReturnData surePay(TblOrder order) {
		if(StringTools.isEmpty(order.getgGoodsName()) || order.getgOrderTotalMoney() == null || order.getgOrderPayMoney() ==
			null || order.getgOrderType() == null || StringTools.isEmpty(order.getgGoodsId()) || order.getgGoodsImg() == null 
			|| order.getgUserId() == null){
			return new ReturnData(12,"参数有误");
		}
		String orderid = WxpayDemoUtils.getRandomString(16);
		if(order.getgOrderType() == 1){
			order.setgOrderNo(orderid);
			order.setgCreatetime(new Date());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			order.setgOrderStatus(0);
			tblOrderMapper.insertSelective(order);
		}else if(order.getgOrderType() == 2){
			//查看会员类型
			TblVipInfo vipInfo = tblVipInfoMapper.selectByPrimaryKey(order.getgGoodsId());
			order.setgOrderNo(orderid);
			order.setgCreatetime(new Date());
			Calendar c = Calendar.getInstance();
			if("月度会员".equals(vipInfo.getgVipName())){
				c.add(Calendar.MONTH, 1);
				order.setgValidityTime(c.getTime());
			}
			if("季度会员".equals(vipInfo.getgVipName())){
				c.add(Calendar.MONTH, 3);
				order.setgValidityTime(c.getTime());
			}
			if("年度会员".equals(vipInfo.getgVipName())){
				c.add(Calendar.YEAR, 1);
				order.setgValidityTime(c.getTime());
			}
			order.setgOrderStatus(0);
			tblOrderMapper.insertSelective(order);
			Map<String,Object> map = new HashMap<>();
			map.put("orderid", orderid);
			map.put("startTime", new Date());
			map.put("endTime", order.getgValidityTime());
			map.put("image", order.getgGoodsImg());
			map.put("goodName", order.getgGoodsName());
			map.put("money", order.getgOrderPayMoney());
			map.put("vipid", order.getgGoodsId());
			return new ReturnData(map,200,"成功");
		}
		return new ReturnData(orderid,200,"成功");
	}

	/**
	 * pc端微信或支付宝或余额支付课程
	 */
	@Override
	public ReturnData PcCoursePay(String orderid, Integer userid,Double money,Integer type,String password) throws Exception {
		System.out.println(password);
		if(orderid == null || userid == null || type == null){
			return new ReturnData(12,"参数有误");
		}
		if(type == 1 || type == 2){
			//修改订单状态
			tblCourseMapper.updateOrderStatus(orderid,null);
			//增加消息表记录
			Map<String,Object> hashMap = new HashMap<>();
			hashMap.put("userid", userid);
			hashMap.put("content", "购买课程");
			hashMap.put("title", "购买课程");
			hashMap.put("type", 2);
			tblCourseMapper.insertMessageRecord(hashMap);
			return new ReturnData(200,"支付成功");
		}else if(type == 3){
			//查看用户余额
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			Double userMoney = (Double) userInfo.get("G_USER_MONEY");
			if(userMoney < money){
				return new ReturnData(20,"账户余额不足，请先充值");
			}
			//RSA解密
			String payWord = RSAUtil.privateDecrypt(password, RSAUtil.getPrivateKey(RSAUtil.privateKey));
			//用户支付密码
			String payPassword = (String) userInfo.get("G_USER_PAY_PASSWORD");
			if(payPassword == null){
				return new ReturnData(12,"请先设置支付密码");
			}
			if(!payPassword.equals(MD5Util.getMD5(payWord))){
				return new ReturnData(10,"支付密码有误，请重新输入");
			}
			//减少用户金额，增加用户积分
			Map<String,Object> map = new HashMap<>();
			map.put("userid", userid);
			map.put("money", money);
			tblCourseMapper.minusUserMoney(map);
			//修改订单状态
			tblCourseMapper.updateOrderStatus(orderid,type.toString());
			/*//根据订单id查询课程id
			Integer[] courseid = tblCourseMapper.selectCourseid(orderid);
			for(int i = 0;i < courseid.length;i++){
				Map<String, Object> courseInfo = tblCourseMapper.selectCourseInfo(courseid[i],null);
				//增加该课程的学习人数
				tblCourseMapper.updateCourseStudyNum(courseid[i],courseInfo.get("G_RELATED_COURSE").toString().split(",").length);
			}*/
			//增加余额明细
			TblUserPurseInfo purseInfo = new TblUserPurseInfo();
			purseInfo.setgContent("购买课程");
			purseInfo.setgCreatetime(new Date());
			purseInfo.setgMoney(money);
			purseInfo.setgStatus(2);
			purseInfo.setgTitle("购买课程");
			purseInfo.setgType(1);
			purseInfo.setgBalance(userMoney - money);
			purseInfo.setgUserid(userid.longValue());
			tblUserPurseInfoMapper.insertSelective(purseInfo);
			return new ReturnData(200,"支付成功");
		}else if(type == 4){
			//查看用户积分
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			Double userIntegral = (Double) userInfo.get("G_USER_INTEGRAL");
			if(userIntegral < money){
				return new ReturnData(20,"积分不足，请先充值");
			}
			//RSA解密
			String payWord = RSAUtil.privateDecrypt(password, RSAUtil.getPrivateKey(RSAUtil.privateKey));
			//用户支付密码
			String payPassword = (String) userInfo.get("G_USER_PAY_PASSWORD");
			if(!payPassword.equals(MD5Util.getMD5(payWord))){
				return new ReturnData(10,"支付密码有误，请重新输入");
			}
			//减少用户积分
			Map<String,Object> map = new HashMap<>();
			map.put("userid", userid);
			map.put("integral", money);
			tblCourseMapper.minusUserIntegral(map);
			//修改订单状态
			tblCourseMapper.updateOrderStatus(orderid,type.toString());
			//增加余额明细
			TblUserPurseInfo purseInfo = new TblUserPurseInfo();
			purseInfo.setgContent("积分兑换课程");
			purseInfo.setgCreatetime(new Date());
			purseInfo.setgMoney(money);
			purseInfo.setgStatus(2);
			purseInfo.setgTitle("积分兑换课程");
			purseInfo.setgType(2);
			purseInfo.setgBalance((Double)userInfo.get("G_USER_INTEGRAL") - money);
			purseInfo.setgUserid(userid.longValue());
			tblUserPurseInfoMapper.insertSelective(purseInfo);
			return new ReturnData(200,"兑换成功");
		}
		return new ReturnData(100,"支付类型有误");
	}

	/**
	 * app端微信或支付宝或余额支付课程
	 */
	@Override
	public ReturnData AppCoursePay(String orderid, Integer userid, Double money,Integer type,String password,
			String body, String subject,String ip) throws Exception {
		ReturnData returnData = new ReturnData();
		if(orderid == null || userid == null || type == null || StringTools.isEmpty(body) || StringTools.isEmpty(subject)){
			return new ReturnData(12,"参数有误");
		}
		if(type == 1){
			returnData = CfbpayDemoUtils.returnAlipayPayParam(body, subject, orderid, money.toString(),userid + "," + orderid,3);
		}else if(type == 2){
			returnData = WxpayDemoUtils.wxPay(body, orderid, money.toString(),ip,userid + "," + orderid,3);
		}else if(type == 3){
			//查看用户余额
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			Double userMoney = (Double) userInfo.get("G_USER_MONEY");
			if(userMoney < money){
				return new ReturnData(20,"账户余额不足，请先充值");
			}
			//用户支付密码
			String payPassword = (String) userInfo.get("G_USER_PAY_PASSWORD");
			if(StringTools.isEmpty(payPassword)){
				return new ReturnData(15,"请先设置支付密码");
			}
			if(!payPassword.equals(MD5Util.getMD5(password))){
				return new ReturnData(10,"支付密码有误，请重新输入");	
			}
			//减少用户金额，增加用户积分
			Map<String,Object> map = new HashMap<>();
			map.put("userid", userid);
			map.put("money", money);
			tblCourseMapper.minusUserMoney(map);
			//修改订单状态
			tblCourseMapper.updateOrderStatus(orderid,type.toString());
			//根据订单id查询课程id
			/*Integer[] courseid = tblCourseMapper.selectCourseid(orderid);
			for(int i = 0;i < courseid.length;i++){
				Map<String, Object> courseInfo = tblCourseMapper.selectCourseInfo(courseid[i],null);
				//增加该课程的学习人数
				tblCourseMapper.updateCourseStudyNum(courseid[i],courseInfo.get("G_RELATED_COURSE").toString().split(",").length);
			}*/
			//增加余额明细
			TblUserPurseInfo purseInfo = new TblUserPurseInfo();
			purseInfo.setgContent("购买课程");
			purseInfo.setgCreatetime(new Date());
			purseInfo.setgMoney(money);
			purseInfo.setgStatus(2);
			purseInfo.setgTitle("购买课程");
			purseInfo.setgType(1);
			purseInfo.setgBalance(userMoney - money);
			purseInfo.setgUserid(userid.longValue());
			tblUserPurseInfoMapper.insertSelective(purseInfo);
			return new ReturnData(200,"支付成功");
		}else{
			return new ReturnData(100,"支付类型有误");
		}
		return returnData;
	}

	/**
     * 学习课程视频获得积分与成长值
     */
	@Override
	public ReturnData insertUserIntegral(Integer userid,Integer lessonid,Integer courseid) {
		if(userid == null || lessonid == null || courseid == null){
			return new ReturnData(12,"参数有误");
		}
		//查看该课时用户是否已经学习
		int nums = tblCourseMapper.selectLessonIsStudy(userid, courseid, lessonid);
		if(nums == 0){
			//查看该课时可得积分与成长值
			Map<String, Object> map = tblCourseMapper.selectLessonIntegral(lessonid);
			//查看用户信息
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			//增加积分明细
			String integral = map.get("get_integral").toString();
			TblUserPurseInfo purseInfo = new TblUserPurseInfo();
			purseInfo.setgContent("本次学习获得" + integral + "积分");
			purseInfo.setgCreatetime(new Date());
			purseInfo.setgMoney(Double.parseDouble(integral));
			purseInfo.setgStatus(1);
			purseInfo.setgTitle("学习课程获得积分");
			purseInfo.setgType(2);
			purseInfo.setgBalance((Double)userInfo.get("G_USER_INTEGRAL") + Double.parseDouble(integral));
			purseInfo.setgUserid(userid.longValue());
			tblUserPurseInfoMapper.insertSelective(purseInfo);
			//增加成长值明细
			String growth_value = map.get("get_growth_value").toString();
			TblUserPurseInfo purseInfo2 = new TblUserPurseInfo();
			purseInfo2.setgContent("本次学习获得" + growth_value + "成长值");
			purseInfo2.setgCreatetime(new Date());
			purseInfo2.setgMoney(Double.parseDouble(growth_value));
			purseInfo2.setgStatus(1);
			purseInfo2.setgTitle("学习课程获得成长值");
			purseInfo2.setgType(3);
			purseInfo2.setgBalance((Integer)userInfo.get("G_USER_GROW") + Double.parseDouble(growth_value));
			purseInfo2.setgUserid(userid.longValue());
			tblUserPurseInfoMapper.insertSelective(purseInfo2);
			//增加用户积分
			Map<String,Object> hm = new HashMap<>();
			hm.put("userid", userid);
			hm.put("integral", Double.parseDouble(map.get("get_integral").toString()));
			hm.put("G_USER_GROW",Integer.parseInt(map.get("get_growth_value").toString()));
			tblCourseMapper.minusUserMoney(hm);
			//增加消息表记录
			Map<String,Object> hashMap = new HashMap<>();
			hashMap.put("userid", userid);
			hashMap.put("content", "学习课程，本次学习获得" + map.get("get_integral") + "积分");
			hashMap.put("title", "学习课程");
			hashMap.put("type", 2);
			tblCourseMapper.insertMessageRecord(hashMap);
		}
		return new ReturnData(200,"成功");
	}

	/**
     * 查看课程评价列表
     */
	@Override
	public ReturnData selectCourseCommentList(Integer courseid,String level) {
		if(courseid == null){
			return new ReturnData(12,"参数有误");
		}
		Map<String,Object> map = new HashMap<>();
		Map<String,Object> hashMap = new HashMap<>();
		map.put("courseid", courseid);
		List<Map<String, Object>> arrayList = tblCourseMapper.selectCourseCommentList(map);
		Integer fiveNum = 0,center = 0,bad = 0;
		//Integer avg = 0;
		for(int i = 0;i < arrayList.size();i++){
			//avg += Integer.parseInt((String) arrayList.get(i).get("level"));
			if("5".equals(arrayList.get(i).get("level").toString())){
				fiveNum++;
			}
			if("2".equals(arrayList.get(i).get("level").toString()) || "3".equals(arrayList.get(i).get("level").toString())
					|| "4".equals(arrayList.get(i).get("level").toString())){
				center++;
			}
			if("1".equals(arrayList.get(i).get("level").toString())){
				bad++;
			}
		}
		DecimalFormat df = new DecimalFormat("#");  
		map.put("level", level);
		List<Map<String, Object>> lists = tblCourseMapper.selectCourseCommentList(map);
		hashMap.put("allNum", arrayList.size());
		hashMap.put("fiveNum", fiveNum);
		hashMap.put("center", center);
		hashMap.put("bad", bad);
		if(arrayList.size() > 0){
			hashMap.put("avg", arrayList.get(0).get("avg"));
		}else{
			hashMap.put("avg", 0);
		}
		hashMap.put("lists", lists);
		return new ReturnData(hashMap,200,"成功");
	}

	/**
     * pc发布课程评价
     */
	@Override
	public ReturnData insertCourseComment(Integer course_id, Integer sender_id, String content, String level) throws Exception{
		if(course_id == null){
			return new ReturnData(12,"参数有误");
		}
		//查看敏感词汇
		String[] words = tblProblemMapper.selectSensitives();
		for(int i = 0;i < words.length;i++){
			String decodedData = RSA.privateDecrypt(words[i], RSA.getPrivateKey(RSA.privateKey));
			if(content.contains(decodedData)){
				return new ReturnData(15,"您所编辑的内容含有敏感词汇，请重新编辑！");
			}
		}
		Map<String,Object> map = new HashMap<>();
		map.put("course_id", course_id); 
		map.put("sender_id", sender_id);
		map.put("content", content);
		map.put("level", level);
		tblCourseMapper.insertCourseComment(map);
		return new ReturnData(200,"成功");
	}

	/**
     * pc端全部作业
     */
	@Override
	public ReturnData selectPcAllJob(Integer courseid) {
		if(courseid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> list = tblCourseMapper.selectPcAllJob(courseid);
		if(list.size() > 0){
			return new ReturnData(list,200,"成功");
		}
		return new ReturnData(100,"暂无数据");
	}

	/**
     * 开始学习
     */
	@Override
	public ReturnData insertLessonStudy(Integer userid, Integer courseid, Integer lessonid) {
		if(userid == null || courseid == null || lessonid == null){
			return new ReturnData(12,"参数有误");
		}
		//查看该课程用户是否已经学习  
		int num = tblCourseMapper.selectUserIsStudy(userid, courseid);
		if(num == 0){
			tblCourseMapper.updateCourseStudyNum(courseid,1);
		}
		//查看该课时用户是否已经学习
		int nums = tblCourseMapper.selectLessonIsStudy(userid, courseid, lessonid);
		if(nums == 0){
			tblCourseMapper.insertLessonStudy(userid, courseid, lessonid);
		}
		return new ReturnData(200,"成功");
	}

	/**
     * 三大分类列表
     */
	@Override
	public ReturnData selectBigSortList(Integer type,Integer param,Integer pageSize, Integer pageNo,Integer userid) {
		List<Map<String, Object>> lists = new ArrayList<>();
		List<Map<String, Object>> userList = new ArrayList<>();
		if(userid != null){
			//查看用户信息
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			String G_USER_OCCUPATION = (String)userInfo.get("G_USER_OCCUPATION");
			if(StringTools.isEmpty(G_USER_OCCUPATION)){
				return new ReturnData(100,"暂无数据");
			}
			String[] split = G_USER_OCCUPATION.split(",");
			for(int i = 0;i < split.length;i++){
				lists = tblCourseMapper.selectBigSortList(2,param);
				for(int j = 0;j < lists.size();j++){
					if(lists.get(j).get("G_TITLE").toString().equals(split[i])){
						userList.add(lists.get(j));
					}
				}
			}
			return new ReturnData(userList,200,"成功");
		}
		if(type == 1){
			//查看职业方向列表
			PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
			lists = tblCourseMapper.selectBigSortList(2,param);
			for(int i = 0;i < lists.size();i++){
				//查看某个列表下面的课时数
				List<Map<String, Object>> arrayList = tblCourseMapper.selectCourseNum(2, (Integer)lists.get(i).get("G_ID"));
				lists.get(i).put("courseNum", arrayList.size());
			}
		}else if(type == 2){
			//查看知识体系列表
			PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
			lists = tblCourseMapper.selectBigSortList(3,param);
			for(int i = 0;i < lists.size();i++){
				Integer courseNum = 0;
				Integer mins = 0;Double money = 0D;
				//查看某个列表下的阶段
				String[] courseid = tblCourseMapper.selectStageList((Integer)lists.get(i).get("G_ID"));
				for(int k = 0;k < courseid.length;k++){
					String[] split = courseid[k].split(",");
					courseNum += split.length;
					for(int y = 0;y < split.length;y++){
						Map<String, Object> courseInfo = tblCourseMapper.selectCourseInfo(Integer.parseInt(split[y]),null);
						if(courseInfo != null){
							mins  += (Integer) courseInfo.get("G_COURSE_TOTAL_DURATION");
							money  += (Double) courseInfo.get("G_COURSE_MONEY");
						}
					}
				}
				lists.get(i).put("courseNum", courseNum);
				lists.get(i).put("mins", mins);
				lists.get(i).put("money", money);
			}
		}else if(type == 3){
			//查看特色课程列表
			PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
			lists = tblCourseMapper.selectBigSortList(4,param);
			for(int i = 0;i < lists.size();i++){
				//查看某个列表下面的课时数
				List<Map<String, Object>> arrayList = tblCourseMapper.selectCourseNum(4, (Integer)lists.get(i).get("G_ID"));
				Double money = 0D;
				for(int j = 0;j < arrayList.size();j++){
					money  += (Double) arrayList.get(j).get("G_COURSE_MONEY");
				}
				lists.get(i).put("courseNum", arrayList.size());
				lists.get(i).put("money", money);
			}
		}else{
			return new ReturnData(10,"类型有误");
		}
		if(param != null && param == 2){
			Collections.sort(lists, new Comparator<Map<String, Object>>() {
				public int compare(Map<String, Object> o1, Map<String, Object> o2) {
					return ((Integer) o2.get("courseNum")).compareTo((Integer) o1.get("courseNum"));
				}
			});
		}
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists, pageInfo.getPages(),(int)pageInfo.getTotal(),200, "成功");
	}

	/**
	 * 查看体系列表详情
	 */
	@Override
	public ReturnData selectBigSortDetails(Integer type, Integer professionid,Integer userid) {
		if(type == null || professionid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = new LinkedList<>();
		Map<String,Object> map = new HashMap<>();
		Map<String,Object> hashMap2 = new HashMap<>();
		Double currentPrice = 0D;		//现价
		Double originalPrice = 0D;		//原价
		Integer vipzhekou = 0;
		String lessonid = "";
		if(type == 1){
			//查看职业方向详情
			//lists = tblCourseMapper.selectBigSortDetails(2, professionid);
			lists = tblCourseMapper.selectJobDirectionDetails(professionid);
			for(int i = 0;i < lists.size();i++){
				lessonid += lists.get(i).get("G_RELATED_COURSE").toString() + ",";
				String[] split = lists.get(i).get("G_RELATED_COURSE").toString().split(",");
				List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(split[0]);
				lists.get(i).put("teacher_name", lessonList.get(0).get("teacher_name"));
			}
			if(!StringTools.isEmpty(lessonid)){
				lessonid = lessonid.substring(0, lessonid.length() - 1);
			}
			List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(lessonid);
			List<Map<String, Object>> lessons = new ArrayList<>(); 
			if(lessonList.size() > 2){
				for(int j = 0;j < 3;j++){
					lessons.add(lessonList.get(j));
				}
				map.put("teacherList", lessons);
			}else{
				map.put("teacherList", lessonList);
			}
			vipzhekou = tblVipInfoMapper.selectJobMaxDiscount();
		}else if(type == 2){
			vipzhekou = tblVipInfoMapper.selectKnowledgeMaxDiscount();
			List<Map<String,Object>> linkList = new LinkedList<>();
			Map<String,Object> hm = new HashMap<>();
			//查看知识体系详情
			lists = tblCourseMapper.selectKnowledgeList(3, professionid);
			if(lists.size() == 0){
				hashMap2 = tblCourseMapper.selectKnowledgeList2(3, professionid);
				hashMap2.put("courseNum", 0);
				hashMap2.put("vipzhekou", vipzhekou);
				hashMap2.put("currentPrice", 0);
				hashMap2.put("originalPrice", 0);
				return new ReturnData(hashMap2,200,"成功");
			}
			int isStudy = 1;
			for(int i = 0;i < lists.size();i++){
				Map<String,Object> hashMap = new HashMap<>();
				List<Map<String,Object>> arrayList = new ArrayList<>();
				String courseid = (String) lists.get(i).get("course_id");
				String[] split = courseid.split(",");
				Integer mins = 0;Integer studyNum = 0;
				for(int j = 0;j < split.length;j++){
					Map<String, Object> courseInfo = tblCourseMapper.selectCourseInfo(Integer.parseInt(split[j]),null);
					if(courseInfo.get("G_COURSE_SCORE") == null){
						courseInfo.put("G_COURSE_SCORE", 0);
					}
					arrayList.add(courseInfo);
					mins  += (Integer) courseInfo.get("G_COURSE_TOTAL_DURATION");
					studyNum  += (Integer) courseInfo.get("G_LEAM_NUM");
					originalPrice  += (Double) courseInfo.get("G_COURSE_MONEY");
					//查看用户是否已购买该系列
					if(isStudy == 1){
						String lesson_id = courseInfo.get("G_RELATED_COURSE").toString();
						String[] lesson = lesson_id.split(",");
						for(int a = 0;a < lesson.length;a++){
							Map<String,Object> hamp = new HashMap<>();
							hamp.put("userid", userid);
							hamp.put("lessonid", lesson[a]);
							int study = tblCourseMapper.selectIsStudy(hamp);
							if(study == 0){
								isStudy = 0;
							}
						}
					}
				}
				hashMap.put("mins", mins);
				hashMap.put("studyNum", studyNum);
				hashMap.put("courseNum", split.length);
				hashMap.put("catalogue", lists.get(i).get("catalogue"));
				hashMap.put("title", lists.get(i).get("title"));
				hashMap.put("stage_content", lists.get(i).get("stage_content"));
				hashMap.put("courseList", arrayList);
				linkList.add(hashMap);
			}
			DecimalFormat df = new DecimalFormat("#.00");
			if((Integer)lists.get(0).get("discount") > 0){
				Integer discount = (Integer)lists.get(0).get("discount");
				currentPrice = Double.parseDouble(df.format(originalPrice * discount.doubleValue() / 100D));
			}else{
				currentPrice = originalPrice;
			}
			hm.put("vipzhekou", vipzhekou);
			hm.put("isStudy", isStudy);
			hm.put("currentPrice", currentPrice.intValue());
			hm.put("originalPrice", originalPrice.intValue());
			hm.put("G_CONTENT", lists.get(0).get("G_CONTENT"));
			hm.put("G_TITLE", lists.get(0).get("G_TITLE"));
			hm.put("G_IMG", lists.get(0).get("G_IMG"));
			hm.put("G_ID", lists.get(0).get("G_ID"));
			hm.put("discount", lists.get(0).get("discount"));
			hm.put("content", lists.get(0).get("content"));
			hm.put("app_img", lists.get(0).get("app_img"));
			hm.put("app_cover", lists.get(0).get("app_cover"));
			hm.put("pc_cover", lists.get(0).get("pc_cover"));
			hm.put("lists", linkList);
			return new ReturnData(hm,200,"成功");
		}else if(type == 3){
			String featrue = systemMapper.selectFeatureCourseid(professionid);
			String[] split = featrue.split(",");
			for(int i = 0;i < split.length;i++){
				Map<String, Object> courseMap = systemMapper.selectFeatureCourseList(split[i]);
				lists.add(courseMap);
			}
			//查看特色课程详情
			//lists = tblCourseMapper.selectBigSortDetails(4, professionid);
			vipzhekou = tblVipInfoMapper.selectPackMaxDiscount();
		}else{
			return new ReturnData(10,"类型有误");
		}
		DecimalFormat df = new DecimalFormat("#.00");
		for(int i = 0;i < lists.size();i++){
			originalPrice += (Double) lists.get(i).get("G_COURSE_MONEY");			
		}
		if(lists.size() == 0){
			return new ReturnData(100,"暂无数据");
		}
		if((Integer)lists.get(0).get("discount") > 0){
			Integer discount = (Integer)lists.get(0).get("discount");
			currentPrice = Double.parseDouble(df.format(originalPrice * discount.doubleValue() / 100D));
		}else{
			currentPrice = originalPrice;
		}
		int isStudy = 1;
		//查看用户是否有购买该课程
		O:for(int a = 0;a < lists.size();a++){
			String lesson_id = lists.get(a).get("G_RELATED_COURSE").toString();
			String[] lesson = lesson_id.split(",");
			for(int i = 0;i < lesson.length;i++){
				Map<String,Object> hashMap = new HashMap<>();
				hashMap.put("userid", userid);
				hashMap.put("lessonid", lesson[i]);
				int study = tblCourseMapper.selectIsStudy(hashMap);
				if(study == 0){
					isStudy = 0;
					break O;
				}
			}
		}
		if(type == 3){
			//查看用户信息
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			if(userInfo != null && userInfo.get("G_USER_SCHOOL") != null && lists.get(0).get("school") != null && userInfo.get("G_USER_SCHOOL").equals(lists.get(0).get("school"))){
				if(lists.get(0).get("end_time") != null && lists.get(0).get("start_time") != null){
					Date endTime = (Date)lists.get(0).get("end_time");
					Date startTime = (Date)lists.get(0).get("start_time");
					if(endTime.getTime() > System.currentTimeMillis() && startTime.getTime() < System.currentTimeMillis()){
						map.put("privilege", 1);
					}
				}
			}
		}
		map.put("isStudy", isStudy);
		map.put("vipzhekou", vipzhekou);
		map.put("currentPrice", currentPrice.intValue());
		map.put("originalPrice", originalPrice.intValue());
		map.put("G_CONTENT", lists.get(0).get("G_CONTENT"));
		map.put("G_TITLE", lists.get(0).get("G_TITLE"));
		map.put("G_IMG", lists.get(0).get("G_IMG"));
		map.put("job_image", lists.get(0).get("job_image"));
		map.put("app_img", lists.get(0).get("app_img"));
		map.put("discount", lists.get(0).get("discount"));
		map.put("content", lists.get(0).get("content"));
		map.put("app_cover", lists.get(0).get("app_cover"));
		map.put("pc_cover", lists.get(0).get("pc_cover"));
		map.put("lists", lists);
		return new ReturnData(map,200,"成功");
	}
	
	/**
	 * APP查看体系列表详情
	 */
	@Override
	public ReturnData APPselectBigSortDetails(Integer type, Integer professionid,Integer userid) {
		if(type == null || professionid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = new ArrayList<>();
		List<Map<String, Object>> chuji = new ArrayList<>();
		List<Map<String, Object>> zhongji = new ArrayList<>();
		List<Map<String, Object>> gaoji = new ArrayList<>();
		List<Map<String, Object>> jichu = new ArrayList<>();
		Map<String, Object> map = new HashMap<>();
		Integer vipzhekou = 0;
		if(type == 1){
			//查看职业方向详情
			lists = tblCourseMapper.selectBigSortDetails(2, professionid);
			vipzhekou = tblVipInfoMapper.selectJobMaxDiscount();
		}/*else if(type == 2){
			//查看知识体系详情
			lists = tblCourseMapper.selectBigSortDetails(3, professionid);
		}else if(type == 3){
			//查看特色课程详情
			lists = tblCourseMapper.selectBigSortDetails(4, professionid);
		}*/else{
			return new ReturnData(10,"类型有误");
		}
		Double currentPrice = 0D;		//现价
		Double originalPrice = 0D;		//原价
		DecimalFormat df = new DecimalFormat("#.00");
		for(int i = 0;i < lists.size();i++){
			originalPrice += (Double) lists.get(i).get("G_COURSE_MONEY");			
			currentPrice += (Double) lists.get(i).get("G_COURSE_MONEY");
			if((Integer)lists.get(i).get("G_COURSE_DIFFICUITY") == 1){
				chuji.add(lists.get(i));
			}
			if((Integer)lists.get(i).get("G_COURSE_DIFFICUITY") == 2){
				zhongji.add(lists.get(i));
			}
			if((Integer)lists.get(i).get("G_COURSE_DIFFICUITY") == 3){
				gaoji.add(lists.get(i));
			}
			if((Integer)lists.get(i).get("G_COURSE_DIFFICUITY") == 4){
				jichu.add(lists.get(i));
			}
		}
		int isStudy = 1;
		//查看用户是否有购买该课程
		O:for(int a = 0;a < lists.size();a++){
			String lesson_id = lists.get(a).get("G_RELATED_COURSE").toString();
			String[] lesson = lesson_id.split(",");
			for(int i = 0;i < lesson.length;i++){
				Map<String,Object> hashMap = new HashMap<>();
				hashMap.put("userid", userid);
				hashMap.put("lessonid", lesson[i]);
				int study = tblCourseMapper.selectIsStudy(hashMap);
				if(study == 0){
					isStudy = 0;
					break O;
				}
			}
		}
		map.put("isStudy", isStudy);
		if(lists.size() > 0){
			if((Integer)lists.get(0).get("discount") > 0){
				String format = df.format(currentPrice * ((Integer)lists.get(0).get("discount") / 100D));
				map.put("currentPrice", format);
			}else{
				map.put("currentPrice", currentPrice);
			}
			map.put("originalPrice", originalPrice);
			map.put("G_IMG", lists.get(0).get("G_IMG"));
			map.put("G_CONTENT", lists.get(0).get("G_CONTENT"));
			map.put("G_TITLE", lists.get(0).get("G_TITLE"));
			map.put("job_image", lists.get(0).get("job_image"));
			map.put("discount", lists.get(0).get("discount"));
			map.put("content", lists.get(0).get("content"));
			map.put("vipzhekou", lists.get(0).get("vipzhekou"));
		}
		map.put("chuji", chuji);
		map.put("zhongji", zhongji);
		map.put("gaoji", gaoji);
		map.put("jichu", jichu);
		return new ReturnData(map,200,"成功");
	}

	 /**
     * 学习中心（查看我的课程）
     */
	@Override
	public ReturnData selectMyCourse(Integer userid,Integer pageSize, Integer pageNo) {
		if(userid == null){
			return new ReturnData(12,"参数有误");
		}
		//PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		//查看我购买未学习的课程
		List<Map<String, Object>> lists = tblCourseMapper.selectMyCourse(userid);
		//查看我学习的课程
		List<Map<String, Object>> arrayList = tblCourseMapper.selectMyStudyCourses(userid);
		if(arrayList.size() > 0){
			lists.addAll(arrayList);
		}
		if(lists.size() > 0){
			for(int i = 0;i < lists.size();i++){
				String str = (String)lists.get(i).get("G_RELATED_COURSE");
				Long studyStatus = (Long)lists.get(i).get("studyNum");
				if(studyStatus == 0){
					lists.get(i).put("studyStatus", "未学习");
				}else if(studyStatus == str.split(",").length){
					lists.get(i).put("studyStatus", "已学完");
				}else{
					lists.get(i).put("studyStatus", "已学" + studyStatus + "/" + str.split(",").length +"课时");
				}
			}
			PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(lists);
			return new ReturnData(lists, pageInfo.getPages(),(int)pageInfo.getTotal(),200, "成功");
		}
		return new ReturnData(100,"暂无数据");
	}

	 /**
     * 学习中心（我的作业）
     */
	@Override
	public ReturnData selectMyLearningWork(Integer userid) {
		if(userid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = tblCourseMapper.selectMyLearningWork(userid);
		if(lists.size() > 0){
			return new ReturnData(lists,200,"成功");
		}
		return new ReturnData(100,"暂无数据");
	}

	/**
     * 学习中心（我的职业）
     */
	@Override
	public ReturnData selectMyJobCourse(Integer userid,Integer type,Integer pageSize, Integer pageNo) {
		if(userid == null || type == null){
			return new ReturnData(12,"参数有误");
		}
		Map<String,Object> map = new HashMap<>();
		map.put("userid", userid);
		if(type == 0){
			map.put("type", null);
		}else{
			map.put("type", type);
		}
		PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		List<Map<String, Object>> lists = tblCourseMapper.selectMyJobCourse(map);
		if(lists.size() == 0){
			return new ReturnData(100,"暂无数据");
		}
		for(int i = 0;i < lists.size();i++){
			Integer lessonids = (Integer) lists.get(i).get("G_LESSON_NUM");
			//查看用户学习有没有购买该课程
			Long courseid = (Long) lists.get(i).get("G_ID");
			String[] lessonid = tblCourseMapper.selectMyStudyCourse(userid,courseid.intValue());
			Integer lessonNum = 0;
			for(int j = 0;j < lessonid.length;j++){
				String[] nums = lessonid[j].split(",");
				lessonNum += nums.length;
			}
			if(lessonids == lessonNum){
				String str = (String)lists.get(i).get("G_RELATED_COURSE");
				Long studyStatus = (Long)lists.get(i).get("studyNum");
				if(studyStatus == 0){
					lists.get(i).put("studyStatus", "未学习");
				}else if(studyStatus == lessonids.longValue()){
					lists.get(i).put("studyStatus", "已学完");
				}else{
					lists.get(i).put("studyStatus", "已学" + studyStatus + "课时");
				}
			}else{
				lists.get(i).put("studyStatus", "未报名");
			}
		}
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(lists);
		return new ReturnData(lists, pageInfo.getPages(),(int)pageInfo.getTotal(),200, "成功");
	}

	  /**
     * 历史记录列表
     */
	@Override
	public ReturnData selectHistoryRecord(Integer userid) {
		if(userid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = tblCourseMapper.selectHistoryRecord(userid);
		if(lists.size() > 0){
			return new ReturnData(lists,200,"成功");
		}
		return new ReturnData(100,"暂无数据");
	}

	 /**
     * 删除历史记录
     */
	@Override
	public ReturnData deleteHistoryRecord(Integer userid) {
		if(userid == null){
			return new ReturnData(12,"参数有误");
		}
		tblCourseMapper.deleteHistoryRecord(userid);
		return new ReturnData(200,"成功");
	}

	 /**
     * 收藏老师
     */
	@Override
	public ReturnData collectTeacher(Integer userid, Integer teacherid) {
		if(userid == null || teacherid == null){
			return new ReturnData(12,"参数有误");
		}
		//收藏之前查看是否已经收藏过
		int flag = tblCourseMapper.selectIsCollectcollectTeacher(userid, teacherid);
		if(flag > 0){
			return new ReturnData(20,"请勿重复收藏");
		}
		tblCourseMapper.collectTeacher(userid, teacherid);
		return new ReturnData(200,"成功");
	}

	 /**
     * 取消收藏老师
     */
	@Override
	public ReturnData cancelCollectTeacher(Integer userid, Integer teacherid) {
		if(userid == null || teacherid == null){
			return new ReturnData(12,"参数有误");
		}
		int flag = tblCourseMapper.cancelCollectTeacher(userid, teacherid);
		if(flag > 0){
			return new ReturnData(200,"成功");
		}
		return new ReturnData(100,"失败");
	}
	
	 /**
     * 查看特色课程分类视频列表
     */
	@Override
	public ReturnData selectFeatureCourseSortList(Integer one_stair_id,Integer two_stair_id,Integer three_stair_id,Integer difficulty,String type,Integer pageSize, Integer pageNo,Integer param) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("one_stair_id", one_stair_id);
		map.put("two_stair_id", two_stair_id);
		map.put("three_stair_id", three_stair_id);
		map.put("difficulty", difficulty);
		map.put("type", type);
		map.put("param", param);
		List<Map<String,Object>> lists = tblCourseMapper.selectFeatureCourseSortList(map);
		//查看特色分类id列表
		Integer[] tpsid = tblCourseMapper.selectFeatureIDSortList();
		PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		List<Map<String,Object>> array = new ArrayList<>();
		for(int i = 0;i < tpsid.length;i++){
			List<Map<String,Object>> arrayList = new ArrayList<>();
			Map<String,Object> hashMap = new HashMap<>();
			for(int j = 0;j < lists.size();j++){
				if(tpsid[i] == lists.get(j).get("G_COURSE_SUPER_TYPE_ID")){
					arrayList.add(lists.get(j));
				}
			}
			Double moneys = 0D;Integer mins = 0,studyNums = 0;
			for(int j = 0;j < arrayList.size();j++){
				moneys += (Double)arrayList.get(j).get("G_COURSE_MONEY");
				mins  += (Integer) arrayList.get(j).get("G_COURSE_TOTAL_DURATION");
				studyNums  += (Integer) arrayList.get(j).get("G_LEAM_NUM");
			}
			if(arrayList.size() > 0){
				hashMap.put("courseNum", arrayList.size());
				hashMap.put("moneys", moneys);
				hashMap.put("mins", mins);
				hashMap.put("studyNums", studyNums);
				hashMap.put("discount", arrayList.get(0).get("discount"));
				hashMap.put("G_TITLE", arrayList.get(0).get("G_TITLE"));
				hashMap.put("G_IMG", arrayList.get(0).get("G_IMG"));
				hashMap.put("sortid", arrayList.get(0).get("sortid"));
				hashMap.put("app_img", arrayList.get(0).get("app_img"));
				hashMap.put("app_cover", arrayList.get(0).get("app_cover"));
				hashMap.put("pc_cover", arrayList.get(0).get("pc_cover"));
				array.add(hashMap);
			}
		}
		if(array.size() > 0){
			if(param != null && param == 2){
				Collections.sort(array, new Comparator<Map<String, Object>>() {
					public int compare(Map<String, Object> o1, Map<String, Object> o2) {
						return ((Integer) o2.get("studyNums")).compareTo((Integer) o1.get("studyNums"));
					}
				});
			}
			PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(array);
			return new ReturnData(array, pageInfo.getPages(),(int)pageInfo.getTotal(),200, "成功");
		}
		return new ReturnData(100, "暂无数据");
	}

	 /**
     * 我的就业班
     */
	@Override
	public ReturnData selectMyEmployment(Integer userid) {
		if(userid == null){
			return new ReturnData(12,"参数有误");
		}
		//查看用户的个人喜好
		Map<String, Object> map = tblCourseMapper.selectUserInfo(userid);
		if(StringTools.isEmpty((String)map.get("G_USER_LIKE"))){
			return new ReturnData(100,"暂无数据");
		}
		String[] courseName = map.get("G_USER_LIKE").toString().split(",");
		List<Map<String, Object>> lists = new ArrayList<>();
		for(int i = 0;i < courseName.length;i++){
			Map<String,Object> hashMap = tblCourseMapper.selectMyEmployment(courseName[i]);
			lists.add(hashMap);
		}
		if(lists.size() == 0){
			return new ReturnData(100,"暂无数据");
		}
		return new ReturnData(lists,200,"成功");
	}

	/**
     * 根据课程名称自动联想筛选    
     */
	@Override
	public ReturnData searchCourseAssociate(String courseName) {
		List<String> lists = tblCourseMapper.searchCourseAssociate(courseName);
		return new ReturnData(lists,200,"成功");
	}

	 /**
     * 学习课程获得成长值
     */
	@Override
	public ReturnData getGrowthValue(Integer courseid, Integer userid) {
		if(courseid == null || userid == null){
			return new ReturnData(12,"参数有误");
		}
		Map<String, Object> map = tblCourseMapper.selectCourseInfo(courseid, null);
		//更新用户成长值
		tblCourseMapper.updateUserGrowthValue(userid,(Integer) map.get("growth_value"));
		return null;
	}

	/**
	 * 三大体系确认订单
	 */
	@Override
	public ReturnData systemSureOrder(Integer userid, Integer professionid, Integer type) {
		if(type == null || professionid == null || userid == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String, Object>> lists = new ArrayList<>();
		List<Map<String,Object>> arrayList = new ArrayList<>();
		Map<String,Object> map = new HashMap<>();
		DecimalFormat df = new DecimalFormat("#.00");
		//查看单个课时会员折扣最高的折扣比
		Integer vipzhekou = 0;
		if(type == 1){
			//查看职业方向详情
			lists = tblCourseMapper.selectBigSortDetails(2, professionid);
			vipzhekou = tblVipInfoMapper.selectJobMaxDiscount();
		}else if(type == 2){
			//查看知识体系详情
			lists = tblCourseMapper.selectKnowledgeList(3, professionid);
			vipzhekou = tblVipInfoMapper.selectKnowledgeMaxDiscount();
		}else if(type == 3){
			//查看特色课程详情
			lists = tblCourseMapper.selectBigSortDetails(4, professionid);
			vipzhekou = tblVipInfoMapper.selectPackMaxDiscount();
		}else{
			return new ReturnData(10,"类型有误");
		}
		if(lists.size() == 0){
			return new ReturnData(100,"暂无数据");
		}
		Double originalPrice = 0D;
		Long convertIntegral = 0l;
		for(int i = 0;i < lists.size();i++){
			if(lists.get(i).get("course_id") == null){
				//查看课程详情
				Map<String, Object> courseInfo = tblCourseMapper.selectCourseDetails(Integer.parseInt(lists.get(i).get("G_ID").toString()));
				//原价
				originalPrice += (Double)courseInfo.get("G_COURSE_MONEY");
				//查看可获得的积分
				convertIntegral += tblCourseMapper.selectSumIntegeal(courseInfo.get("G_RELATED_COURSE").toString());
				//查看课程下面的课时数
				List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(courseInfo.get("G_RELATED_COURSE").toString());
				//查看用户已经购买的课时
				List<Map<String, Object>> courseList = tblCourseMapper.selectPurchaseLesson(userid);
				for(int y = 0;y < courseList.size();y++){
					String lesson = (String)courseList.get(y).get("G_GOODS_ID");
					String[] lessonid = lesson.split(",");
					for(int j = 0;j < lessonList.size();j++){
						for(int k = 0;k < lessonid.length;k++){  
							if(lessonList.get(j).get("G_ID").toString().equals(lessonid[k])){  
								lessonList.get(j).put("TOTAL_MONEY", courseList.get(y).get("G_ORDER_PAY_MONEY"));
								arrayList.add(lessonList.get(j));
							}
						}
					}
				}
			}else{
				String[] split = lists.get(i).get("course_id").toString().split(",");
				for(int a = 0;a < split.length;a++){
					//查看课程详情
					Map<String, Object> courseInfo = tblCourseMapper.selectCourseDetails(Integer.parseInt(split[a]));
					//原价
					originalPrice += (Double)courseInfo.get("G_COURSE_MONEY");
					//查看可获得的积分
					convertIntegral += tblCourseMapper.selectSumIntegeal(courseInfo.get("G_RELATED_COURSE").toString());
					//查看课程下面的课时数
					List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(courseInfo.get("G_RELATED_COURSE").toString());
					//查看用户已经购买的课时
					List<Map<String, Object>> courseList = tblCourseMapper.selectPurchaseLesson(userid);
					for(int y = 0;y < courseList.size();y++){
						String lesson = (String)courseList.get(y).get("G_GOODS_ID");
						String[] lessonid = lesson.split(",");
						for(int j = 0;j < lessonList.size();j++){
							for(int k = 0;k < lessonid.length;k++){  
								if(lessonList.get(j).get("G_ID").toString().equals(lessonid[k])){  
									lessonList.get(j).put("TOTAL_MONEY", courseList.get(y).get("G_ORDER_PAY_MONEY"));
									arrayList.add(lessonList.get(j));
								}
							}
						}
					}
				}
			}
			
		}
		HashSet h = new HashSet<>(arrayList);   
		arrayList.clear();   
		arrayList.addAll(h);   
		Double purchase = 0D;	//已购视频的总价格
		for(int i = 0;i < arrayList.size();i++){
			purchase += (Double)arrayList.get(i).get("TOTAL_MONEY");
		}
		//现价
		Double currentPrice = originalPrice - purchase; 
		if((Integer)lists.get(0).get("discount") > 0){
			Integer discount = (Integer)lists.get(0).get("discount");
			currentPrice = Double.parseDouble(df.format(currentPrice * discount.doubleValue() / 100D));
		}
		Double vipmoney = Double.parseDouble(df.format(currentPrice * vipzhekou.doubleValue() / 100D));
		//查看用户信息(是否是vip)
		Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
		Map<String, Object> vipInfo = tblVipInfoMapper.selectVipInfo((Integer)userInfo.get("G_USER_IS_VIP"));
		if(vipInfo != null){
			if((Long)userInfo.get("isvip") > 0){
				Integer vipDiscount = null;
				if(type == 1){
					vipDiscount = (Integer) vipInfo.get("job_course_discount");   	
				}else if(type == 2){
					vipDiscount = (Integer) vipInfo.get("knowledge_course_discount");   	
				}else if(type == 3){
					vipDiscount = (Integer) vipInfo.get("pack_course_discount");   	
				}
				if(vipDiscount != null){
					currentPrice = Double.parseDouble(df.format(currentPrice * (vipDiscount.doubleValue() / 100D)));
					map.put("vipDiscount", vipDiscount);
				}
			}
		}
		//查看平台费用折扣
		Integer platformDiscount = tblCourseMapper.selectPlatformDiscount();
		if(platformDiscount != null && platformDiscount > 0){
			currentPrice = currentPrice * (platformDiscount.doubleValue() / 100D);
		}
		map.put("integral", userInfo.get("G_USER_INTEGRAL"));
		map.put("vipMoney", currentPrice.intValue() - vipmoney.intValue());
		map.put("purchase", purchase.intValue());
		map.put("currentPrice", currentPrice.intValue());
		map.put("originalPrice", originalPrice.intValue());
		map.put("convertIntegral", convertIntegral);
		map.put("isvip", userInfo.get("isvip"));
		map.put("G_TITLE", lists.get(0).get("G_TITLE"));
		map.put("G_IMG", lists.get(0).get("G_IMG"));
		map.put("job_image", lists.get(0).get("job_image"));
		map.put("discount", lists.get(0).get("discount"));
		map.put("lists", arrayList);
		return new ReturnData(map,200,"成功");
	}

	/**
	 * 三大体系确认订单
	 */
	@Override
	public ReturnData systemSurePay(TblOrder order) {
		if(StringTools.isEmpty(order.getgGoodsName()) || order.getgOrderTotalMoney() == null || order.getgOrderPayMoney() ==
			null || StringTools.isEmpty(order.getgGoodsId()) || order.getgGoodsImg() == null || order.getgUserId() == null || order.getSystem_type() == null){
			return new ReturnData(12,"参数有误");
		}
		List<Map<String,Object>> arrayList = new ArrayList<>();
		String[] goodid = order.getgGoodsId().split(";");
		for(int i = 0;i < goodid.length;i++){
			String[] split = goodid[i].split(":");
			//查看课程下面的课时数
			List<Map<String, Object>> lessonList = tblCourseMapper.selectCoursebyLesson(split[1]);
			//查看用户已经购买的课时
			List<Map<String, Object>> courseList = tblCourseMapper.selectPurchaseLesson(order.getgUserId().intValue());
			for(int y = 0;y < courseList.size();y++){
				String lesson = (String)courseList.get(y).get("G_GOODS_ID");
				String[] lessonid = lesson.split(",");
				for(int j = 0;j < lessonList.size();j++){
					for(int k = 0;k < lessonid.length;k++){  
						if(lessonList.get(j).get("G_ID").toString().equals(lessonid[k])){  
							arrayList.add(lessonList.get(j));
						}
					}
				}
			}
		}
		HashSet set = new HashSet<>(arrayList);   
		arrayList.clear();   
		arrayList.addAll(set); 
		String orderid = WxpayDemoUtils.getRandomString(16);
		for(int i = 0;i < goodid.length;i++){
			String[] split = goodid[i].split(":");
			for(int j = 0;j < arrayList.size();j++){
				List<String> lists = new ArrayList<String>();    
				for(String t : split[1].split(",")){    
					lists.add(t);    
				}   
				for(int k = 0;k < lists.size();k++){
					if(arrayList.get(j).get("G_ID").toString().equals(lists.get(k))){
						lists.remove(k);
					}
				}
				String[] strings = new String[lists.size()];
				String[] array = lists.toArray(strings);
				split[1] = StringUtils.join(array,",");
			}
			if(StringTools.isEmpty(split[1])){
				continue;
			}
			order.setgOrderNo(orderid);
			order.setgCreatetime(new Date());
			order.setgOrderStatus(0);
			order.setgOrderType(1);
			order.setgGoodsId(split[1]);
			order.setgCourseId(Integer.parseInt(split[0]));
			tblOrderMapper.insertSelective(order);
		}
		return new ReturnData(orderid,200,"成功");
	}

	/**
	 * pc端微信或支付宝或余额支付系列课程
	 */
	@Override
	public ReturnData PcSystemCoursePay(String orderid, Integer userid, Double money, Integer type, String password) throws Exception {
		if(orderid == null || userid == null || type == null || money == null){
			return new ReturnData(12,"参数有误");
		}
		if(type == 1 || type == 2){
			//修改订单状态
			tblCourseMapper.updateOrderStatus(orderid,null);
			//增加消息表记录
			Map<String,Object> hashMap = new HashMap<>();
			hashMap.put("userid", userid);
			hashMap.put("content", "购买课程");
			hashMap.put("title", "购买课程");
			hashMap.put("type", 2);
			tblCourseMapper.insertMessageRecord(hashMap);
			return new ReturnData(200,"支付成功");
		}else if(type == 3){
			//查看用户余额
			Map<String, Object> userInfo = tblCourseMapper.selectUserInfo(userid);
			Double userMoney = (Double) userInfo.get("G_USER_MONEY");
			if(userMoney < money){
				return new ReturnData(20,"账户余额不足，请先充值");
			}
			//RSA解密
			String payWord = RSAUtil.privateDecrypt(password, RSAUtil.getPrivateKey(RSAUtil.privateKey));
			//用户支付密码
			String payPassword = (String) userInfo.get("G_USER_PAY_PASSWORD");
			if(payPassword == null){
				return new ReturnData(12,"请先设置支付密码");
			}
			if(!payPassword.equals(MD5Util.getMD5(payWord))){
				return new ReturnData(10,"支付密码有误，请重新输入");
			}
			//减少用户金额，增加用户积分
			Map<String,Object> map = new HashMap<>();
			map.put("userid", userid);
			map.put("money", money);
			tblCourseMapper.minusUserMoney(map);
			//修改订单状态
			tblCourseMapper.updateOrderStatus(orderid,type.toString());
			//根据订单id查询课程id
			//Integer courseid = tblCourseMapper.selectCourseid(orderid);
			//将该课程的学习人数加1
			//tblCourseMapper.updateCourseStudyNum(courseid);
			//增加余额明细
			TblUserPurseInfo purseInfo = new TblUserPurseInfo();
			purseInfo.setgContent("购买课程");
			purseInfo.setgCreatetime(new Date());
			purseInfo.setgMoney(money);
			purseInfo.setgStatus(2);
			purseInfo.setgTitle("购买课程");
			purseInfo.setgType(1);
			purseInfo.setgBalance(userMoney - money);
			purseInfo.setgUserid(userid.longValue());
			tblUserPurseInfoMapper.insertSelective(purseInfo);
			return new ReturnData(200,"支付成功");
		}
		return new ReturnData(100,"支付类型有误");
	}

	/**
	 * app支付三大体系课程
	 */
	@Override
	public ReturnData AppSystemCoursePay(String orderid, Integer userid, Double money, Integer type, String body,
			String subject, String ip) throws Exception {
		ReturnData returnData = new ReturnData();
		if(orderid == null || userid == null || type == null || StringTools.isEmpty(body) || StringTools.isEmpty(subject)){
			return new ReturnData(12,"参数有误");
		}
		if(type == 1){
			returnData = CfbpayDemoUtils.returnAlipayPayParam(body, subject, orderid, money.toString(),userid + "," + orderid,3);
		}else if(type == 2){
			returnData = WxpayDemoUtils.wxPay(body, orderid, money.toString(),ip,userid + "," + orderid,3);
		}else{
			return new ReturnData(100,"支付类型有误");
		}
		return returnData;
	}

	/**
     * 职业方向列表
     */
	@Override
	public ReturnData selectJobList() {
		List<Map<String, Object>> lists = tblCourseMapper.selectJobList();
		return new ReturnData(lists,200,"成功");
	}
	
	/**
	 * 线下课程或直播列表
	 */
	@Override
	public ReturnData getOtherCourseList(Integer type) {
		// TODO Auto-generated method stub
		List<TblOtherCourse> list = tblOtherCourseMapper.selectList(type);
		return new ReturnData(list,200,"其他课程列表");
	}

	 /**
     * 填写表单
     */
	@Override
	public ReturnData insertForm(String username, String phone, String school, String grade, String specialty) {
		if(StringTools.isEmpty(username) || StringTools.isEmpty(phone) || StringTools.isEmpty(school) || StringTools.isEmpty(grade) || StringTools.isEmpty(specialty)){
			return new ReturnData(12,"参数有误");
		}
		if (!phone.matches("^(13|15|17|18)[0-9]{9}$")) {
			return new ReturnData(101, "请输入正确手机号");
		}
		Map<String,Object> map = new HashMap<>();
		map.put("username", username);
		map.put("phone", phone);
		map.put("school", school);
		map.put("grade", grade);
		map.put("specialty", specialty);
		tblCourseMapper.insertForm(map);
		int flag = tblCourseMapper.selectPhoneIsExist(phone);
		if(flag > 0){
			return new ReturnData(200,"成功");
		}else{
    		tblCourseMapper.insertUser(phone,UUIDUtil.getFixLenthInt(8));
			return new ReturnData(200,"成功");
		}
	}
	
}
